//
//  GQProfileController.m
//  GuQu
//
//  Created by HELIUM STAR on 15/5/7.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQProfileController.h"
#import "GQProfileHeaderView.h"
#import "GQRegisterDetailController.h"
#import "GQProfileSettingController.h"
#import "GQConcernAndFansController.h"
#import "GQProfileMyDistributeController.h"
#import "GQProfileMyCollectionController.h"
#import "GQProfileCodeController.h"
#import "GQProfileAuthenticationController.h"
#import "GQProfileInviteFriendController.h"

@interface GQProfileController () <UITableViewDataSource, UITableViewDelegate, GQProfileHeaderViewDelegate>

@property (strong, nonatomic) NSMutableArray *imagesArrM;
@property (strong, nonatomic) NSMutableArray *titlesArrM;

@end

@implementation GQProfileController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBar.frame = CGRectZero;
    self.title = @"林志颖";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"setting"] style:UIBarButtonItemStylePlain target:self action:@selector(settingItemDidClick)];
    
     GQProfileHeaderView *headerView = [[GQProfileHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 152 + kNavigatationBarHeight)];
    headerView.delegate = self;
    [self.view addSubview:headerView];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1DidClick)];
    [headerView.concernView addGestureRecognizer:tap1];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2DidClick)];
    [headerView.fansView addGestureRecognizer:tap2];


    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headerView.frame), self.view.width, self.view.height - kNavigatationBarHeight - 152 - 20) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:tableView];
    
}

- (void)tap1DidClick
{
    self.navigationController.navigationBar.hidden = NO;
    GQConcernAndFansController *GQCAFC = [[GQConcernAndFansController alloc] initWithStyle:UITableViewStylePlain];
    [self.navigationController pushViewController:GQCAFC animated:YES];
}

- (void)tap2DidClick
{
    self.navigationController.navigationBar.hidden = NO;
    GQConcernAndFansController *GQCAFC = [[GQConcernAndFansController alloc] initWithStyle:UITableViewStylePlain];
    [self.navigationController pushViewController:GQCAFC animated:YES];
}

- (void)settingItemDidClick
{
    
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
}

- (void)GQProfileHeaderViewSettingDidClick:(UIButton *)btn
{
    self.navigationController.navigationBar.hidden = NO;
    GQProfileSettingController *GQPSC = [[GQProfileSettingController alloc] initWithStyle:UITableViewStyleGrouped];
    [self.navigationController pushViewController:GQPSC animated:YES];
}

- (void)GQProfileHeaderViewEditDidClick:(UIButton *)btn
{
    self.navigationController.navigationBar.hidden = NO;
    GQRegisterDetailController *GQRDC = [[GQRegisterDetailController alloc] init];
    GQRDC.type = @"edit";
    [GQRDC.registerInfoArray insertObject:@"生日" atIndex:4];
    [self.navigationController pushViewController:GQRDC animated:YES];
    GQRDC.title = @"编辑资料";
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.imagesArrM.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.imagesArrM[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"flag"];
    cell.imageView.image = [UIImage imageNamed:self.imagesArrM[indexPath.section][indexPath.row]];
    cell.textLabel.text = self.titlesArrM[indexPath.section][indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 20;
    }
    if (section == 1) {
        return 1;
    }
    return 0;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 0) {
        GQProfileMyDistributeController *GQPMDC = [[GQProfileMyDistributeController alloc] init];
        [self.navigationController pushViewController:GQPMDC animated:YES];
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        GQProfileMyCollectionController *GQPMCC = [[GQProfileMyCollectionController alloc] init];
        [self.navigationController pushViewController:GQPMCC animated:YES];
    }
    if (indexPath.section == 0 && indexPath.row == 2) {
        GQProfileCodeController *GQPCC = [[GQProfileCodeController alloc] init];
        [self.navigationController pushViewController:GQPCC animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row == 1) {
        GQProfileAuthenticationController *GQPAC = [[GQProfileAuthenticationController alloc] init];
        [self.navigationController pushViewController:GQPAC animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        GQProfileInviteFriendController *GQPIFC = [[GQProfileInviteFriendController alloc] init];
        [self.navigationController pushViewController:GQPIFC animated:YES];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
}

- (NSMutableArray *)imagesArrM
{
    if (_imagesArrM == nil) {
        NSArray *arr1 = [NSArray arrayWithObjects:@"profile_status", @"profile_collection", @"profile_code", @"profile_swap",  nil];
        NSArray *arr2 = [NSArray arrayWithObjects:@"profile_addFriend", @"profile_vertify", nil];
        _imagesArrM = [NSMutableArray array];
        [_imagesArrM addObject:arr1];
        [_imagesArrM addObject:arr2];
    }
    return _imagesArrM;
}

- (NSMutableArray *)titlesArrM
{
    if (_titlesArrM == nil) {
        _titlesArrM = [NSMutableArray array];
        NSArray *title1 = [NSArray arrayWithObjects:@"我的发布", @"我的收藏", @"我的二维码", @"扫一扫(添加好友)", nil];
        NSArray *title2 = [NSArray arrayWithObjects:@"查找邀请好友", @"申请实名认证", nil];
        [_titlesArrM addObject:title1];
        [_titlesArrM addObject:title2];
    }
    return _titlesArrM;
}

@end
